package com.java.netty.nio.netty.protocoltcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @Author: Dgg
 * @Date: 2022/1/25 21:38
 */
public class MyMessageEncoder extends MessageToByteEncoder<MessageProtoCol> {

	@Override
	protected void encode(ChannelHandlerContext channelHandlerContext, MessageProtoCol messageProtoCol, ByteBuf byteBuf) throws Exception {
		System.out.println("messageProtocol Encoder被调用");
		byteBuf.writeInt(messageProtoCol.getLen());
		byteBuf.writeBytes(messageProtoCol.getBytes());
	}
}
